package com.situ.day21.db;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Properties;

public class DBTest {
    @Test
    public void test() throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //面向接口编程
        //MySql mySql = new MySql();
        /*IDB db = new MySql();
        db.getConnection();
        db = new Oracle();
        db.getConnection();*/

        FileInputStream fileInputStream = new FileInputStream("./src/com/situ/day21/db/db.properties");
        Properties properties = new Properties();
        properties.load(fileInputStream);
        String className = properties.getProperty("className");
        Class clazz = Class.forName(className);
        //如果要调用无参构造方法，可以简写成
        IDB db = (IDB) clazz.newInstance();
//        Constructor constructor = clazz.getConstructor();
//        IDB db = (IDB) constructor.newInstance();
        db.getConnection();

    }
}
